import { Sprite_FrameBase } from "@/sprites/Sprite_FrameBase.js";

export class Sprite_Cursor extends Sprite_FrameBase{
    static texture=null;
    static sourceName='';
    constructor(width,height){
        super({
            name:'Cursor',
            width,
            height,
            left:4,
            top:4,
            right:4,
            bottom:4
        });
        this.active=true;
        this._animationCount=0;
    }

    isActive(){return this.active;}
    activate(){
        this.show();
        this.active=true;
    }
    deactivate(){this.active=false;}

    hide(){
        this.visible=false;
        this.deactivate();
    }
    show(){this.visible=true;}

    update() {
        if(this.active&&this.visible){
            ++this._animationCount;
            let blinkCount = this._animationCount % 40;
            let cursorOpacity = 255;
            if (blinkCount < 20) {
                cursorOpacity -= blinkCount * 8;
            } else {
                cursorOpacity -= (40 - blinkCount) * 8;
            }
            this.alpha = cursorOpacity/255;
        }
    }
}